

/*
 * Restore class
 * This class represents restoring a serialzied Greenhouse, applying the fix, and
 * starting off where where it errored.
 * 
 * James Zhang
 * ID: 3069886
 * July 17, 2012
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class Restore
{
    /**
     * Default Constructor
     * @param filename - Path of the serialized GreenhouseControls
     * @param g - The GUI which it outputs to
     */
    public Restore( String filename )
    {
        try
        {
            //Deserializes the object from said path
            FileInputStream file = new FileInputStream( new File( filename ) );
            ObjectInputStream restoreObj = new ObjectInputStream( file );
            GreenhouseControls restoreGc = ( GreenhouseControls ) restoreObj.readObject();
            restoreObj.close();

            //Prints state of the restored object
            restoreGc.getState();

            System.out.println( "Applying proper fix..." );
            //Gets error code and applies appropriate fix
            restoreGc.getFixable( restoreGc.getError() );

            System.out.println( "" );
            System.out.println( "Starting events from error..." );
            System.out.println( "" );

            //Starting events again
            restoreGc.restoreEvent();

        } catch ( IOException e )
        {
            e.printStackTrace();
        } catch ( ClassNotFoundException ex )
        {
            System.out.println( "Class was not found\n" );
        }
    }
}